package com.gpslw.mvc.controller;

import com.gpslw.mvc.bean.BuildingRoom;
import com.gpslw.mvc.service.BuildingRoomService;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@RequestMapping("/buildingroom")
@RestController
public class BuildingRoomController {

    @Autowired
    protected BuildingRoomService buildingRoomService;

    @PostMapping("/insertBatch")
    public String insertBatch(){
        buildingRoomService.saveBatch(generateBuildingRoom(), 100);
        return "插入success";
    }

    private List<BuildingRoom> generateBuildingRoom(){
        List<BuildingRoom> buildingRooms = new ArrayList<>();
        for (int i = 0; i < 1000; i++) {
            BuildingRoom buildingRoom = new BuildingRoom();
            buildingRoom.setRoomArea(BigDecimal.valueOf(RandomUtils.nextDouble() * 100)).setRoomCode("A0"+String.valueOf(i))
                    .setProjectId(i%2L);
            buildingRooms.add(buildingRoom);
        }
        return buildingRooms;
    }
}
